

#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <algorithm>
#include <memory>
using namespace std;

void sum(int a,int b){
    cout<<"sum is :"<<a+b<<endl;
}
class Foo
{
public:
    void methodA(){
        cout<<"methodA"<<endl;
    }
    void methodInt(int a){
        cout<<"methodInt:"<<a<<endl;
    }
};
class Bar
{
public:
    void methodB(){
        cout<<"methodB"<<endl;
    }
};

int main(){
    boost::function<void(int,int)> f;
    f=&sum;
    f(3,4);

    boost::function<void()> f1; // 无参数，无返回值

    Foo foo;
    f1 = boost::bind(&Foo::methodA, &foo);
    f1(); // 调用 foo.methodA();
    Bar bar;
    f1 = boost::bind(&Bar::methodB, &bar);
    f1(); // 调用 bar.methodB();

    f1 = boost::bind(&Foo::methodInt, &foo, 42);
    f1(); // 调用 foo.methodInt(42);

    boost::function<void(int)> f2; // int 参数，无返回值
    f2 = boost::bind(&Foo::methodInt, &foo, _1);
    f2(53); // 调用 foo.methodInt(53);
}



